package com.Smart.smartscals.Fragment;

import javax.crypto.Mac;

import com.Smart.smartscals.Activity.ActivityGuide;
import com.Smart.smartscals.Activity.R;
import com.Smart.smartscals.Adapter.ArrayWheelAdapter;
import com.Smart.smartscals.CustomView.CustomScrovieView;
import com.Smart.smartscals.CustomView.CustomWheelView;
import com.Smart.smartscals.Entity.EntityWheelView;
import com.Smart.smartscals.Utils.Const;
import com.Smart.smartscals.Utils.Tools;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

public class FragmentGudeHeight extends BaseFragment {

	private CustomScrovieView mCustomScrovieView;
	private EntityWheelView entityWheelView;
	private int heightCm;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

	}

	@Override
	public void onViewCreated(View view, Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		initView();
		initParam();
		setListener();
	}

	private void initParam() {
		mActivityGuide = (ActivityGuide) this.getActivity();
		ArrayWheelAdapter<String> arrayWheelAdapter = new ArrayWheelAdapter<String>(
				new String[] { "00", "01", "02", "03", "04", "05", "06", "07",
						"08", "09", "10", "11", "12", "13", "14", "15", "16",
						"17", "18", "19", "20", "21", "22", "23", "24", "25",
						"26", "27", "28", "29", "30", "31", "32", "33", "34",
						"35", "36", "37", "38", "39", "40", "41", "42", "43",
						"44", "45", "46", "47", "48", "49", "50", "51", "52",
						"53", "54", "55", "56", "57", "58", "59", "60", "61",
						"62", "63", "64", "65", "66", "67", "68", "69", "70",
						"71", "72", "73", "74", "75", "76", "77", "78", "79",
						"80", "81", "82", "83", "84", "85", "86", "87", "88",
						"89", "90", "91", "92", "93", "94", "95", "96", "97",
						"98", "99", "00", "01", "02", "03", "04", "05", "06",
						"07", "08", "09", "10", "11", "12", "13", "14", "15",
						"16", "17", "18", "19", "20", "21", "22", "23", "24",
						"25", "26" });

		entityWheelView = new EntityWheelView("1",
				this.getString(R.string.guide_height_unit_m),
				this.getString(R.string.guide_height_unit_cm), true,
				Const.GUIDSEXCHOICEPARAMSIZE, Const.GUIDSEXCHOICEPARAMUNITSIZE,
				arrayWheelAdapter);
		mCustomScrovieView.startMyTration(entityWheelView);
	}

	private void setListener() {
		initNextLastBtnListener();
		layBack.setOnClickListener(this);
		// 添加监听事件
		mCustomScrovieView
				.setOnWeelChangeListener(mCustomScrovieView.new WeelChangeListener() {

					@Override
					public void onWeelChangeListener(CustomWheelView wheel,
							int oldValue, int newValue) {

						Tools.setLog("---->mCustomViewWheelListener:"
								+ newValue + "  " + oldValue);
						if (newValue == 100) {
							mCustomScrovieView.SetFirstTv("2");
						} else if (newValue == 99) {
							mCustomScrovieView.SetFirstTv("1");
						} else if (newValue == 0) {
							mCustomScrovieView.SetFirstTv("1");
						}
						heightCm = newValue;

					}
				});
	}

	private void initView() {
		mCustomScrovieView = (CustomScrovieView) mView
				.findViewById(R.id.guide_choiceheight_whellview);
		initButton();
		initTopImgBtn();
		initToastTvBigSmall();
		setTextSmallBig(R.string.guide_heghtis, R.string.guide_heightisornot);

	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView = inflater.inflate(R.layout.fragment_guide_choiceheight, null);
		return mView;
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);

		switch (v.getId()) {
		case R.id.btn_guide_back:
			backDoJob(this);
			break;

		case R.id.btn_guide_next:
			nextDoJOb();
			break;
		case R.id.guide_linelayout_top_back:
			backDoJob(this);
			break;
		default:
			break;
		}
	}

	private void nextDoJOb() {
		// mActivityGuide.getmFragmentTransaction().

		Tools.startFragment(mActivityGuide,
				mActivityGuide.getmFragmentGudeAge());
		heightCm = mCustomScrovieView.getCurrentItem() + 100;
		mActivityGuide.getmEntityUserInfo().setUserHeight(heightCm + "");
	}

}
